<?php

use think\migration\Migrator;
use think\migration\db\Column;

class StoreCart extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        //创建购物车(cart)表
        $this->table("store_cart", ['comment' => '门店用户-购物车'])
             ->addColumn('store_user_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'id', 'comment' => '用户id'])
             ->addColumn('goods_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'user_id', 'comment' => '产品id'])
             ->addColumn('goods_rule_id', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'goods_id', 'comment' => '产品规格id'])
             ->addColumn('quantity', 'integer', ['limit' => 10, 'default' => 0, 'after' => 'goods_rule_id', 'comment' => '数量'])
             ->addColumn('money', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, 'after' => 'quantity', 'comment' => '单价金额'])
             ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0.00, 'after' => 'money', 'comment' => '总金额'])
             ->addColumn('status', 'integer', ['limit' => 1, 'default' => 1, 'after' => 'amount', 'comment' => '状态 1:正常'])
             ->addColumn('create_time', 'integer', ['limit' => 10, 'after' => 'status', 'default' => 0, 'comment' => '创建时间'])
             ->addColumn('update_time', 'integer', ['limit' => 10, 'after' => 'create_time', 'default' => 0, 'comment' => '更新时间'])
             ->addColumn('delete_time', 'integer', ['limit' => 10, 'after' => 'update_time', 'default' => 0, 'comment' => '删除时间'])
             ->create();
    }
}
